import { FactoryTaskHelper } from "GameLoop/WorldState/EntityManager/Entitys/room/factory/FactoryTaskHelper";
import { State } from "framework/FSM/AState";
 
export class  FactoryProducing<T extends IStateArg<Room>> extends State<T>
{

    public getActions(arg:T):Action[]
    {

        const actions:Action[] = [];
        const curtask = arg.entity.getTaskByType("factory")[0] ;
        const task = curtask.data;
        const coreEntity = arg.entity.getEntity("CoreEntity");
        const toptask = FactoryTaskHelper.Top(task.arg);
        const factory = coreEntity.Factory;
        if(toptask && factory)
        {

            if(toptask.amount<=toptask.number)
            {

                // 反应完成进入下一个阶段
                FactoryTaskHelper.Pop(task.arg);
            }
            else
            {

                // 继续生产
                if(factory.cooldown == 0)
                {
                   const res = factory.produce( toptask.target);

                   if( res == OK)
                   {
                        toptask.number+=COMMODITIES[ toptask.target].amount;    // 每次生产完成则数量增加一次反应的数量
                    //    global.LogError(`FactoryProducing:produce error ${res}`);
                        curtask.ttl +=500;
                   }
                }
            }

        }
        return actions;
    }
}
